package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.Immunization;
import com.bingo.entity.Meteorology;
import com.bingo.entity.WaterQuality;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.service.WaterQualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/waterQuality")
public class WaterQualityController {
    private WaterQualityService waterQualityService;
    @Autowired
    public void setWaterQualityService(WaterQualityService waterQualityService) {
        this.waterQualityService = waterQualityService;
    }

    @PostMapping("/record")
    public R waterQualityRecord(@RequestBody ReqForm reqForm) {
        return R.success(waterQualityService.selectWaterQualityRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }

    @PostMapping("/delete")
    public R deleteWaterQualityRecord(@RequestBody WaterQuality waterQuality){
        boolean delete =waterQualityService.deleteWaterQualityRecord(waterQuality);
        if (!delete){
            return R.error("删除失败！");
        }
        return R.success("删除成功！");
    }
    @PostMapping("/add")
    public R addWaterQualityRecord(@RequestBody WaterQuality waterQuality) {
        return waterQualityService.add(waterQuality);
    }
    @PostMapping("/update")
    public R updateWaterQualityRecord(@RequestBody WaterQuality waterQuality) {
        return R.success(waterQualityService.update(waterQuality));
    }

}
